<template>
	<view class="">
		<image src="/static/denglu.png" mode="widthFix" class="image"></image>
		<view class="bgfff bgt mt-230 posire flex-ju-c">
			<image mode="widthFix" class="image width80 pt50" src="/static/denglutxt.png"></image>
		</view>
		<view class="bgfff pt50 posire">
			<view class="con ">
				<view class="con">
					<input class="bgF6F7F8 ra20 pg25" maxlength="11" v-model="form.phone" placeholder-style="color:#999;font-size:27rpx;" placeholder="请输入手机号"/>
					<input class="bgF6F7F8 ra20 pg25 mt30" placeholder-style="color:#999;font-size:27rpx;" v-if="type" type="password" v-model="form.password" placeholder="请输入密码"/>
					<view v-else class=" mt30 bgF6F7F8 ra20 posire pg25">
						<view @click="yanzhengma" v-if="!butdisabled" class="copde flex-ju-c size27 posiab zindex50 right50 ">发送验证码</view>
						<view v-else class="copde flex-ju-c size27 posiab zindex50 right50">已发送 {{ codetxt }}</view>
						<input class="   "  placeholder-style="color:#999;font-size:27rpx;" v-model="form.phone_code" placeholder="请输入验证码" />
					</view>
					<!-- <input class="bgF6F7F8 ra20 pg25 mt30" placeholder-style="color:#999;font-size:27rpx;" v-model="form.invite_code" placeholder="请输入邀请码(选填)"/> -->
					<view class="mt30 flex-ju-b size26">
						<view v-if="type==1"  @click="denglu(0)">验证码登录</view>
						
						<view v-else @click="denglu(1)">密码登录</view>
						
						<view  class="color999"><text @click="navto('/pages/user/password?type=password')">忘记密码</text>   I  <text @click="navto('register')">注册账号</text> </view>
					</view>
					
					<!-- <radio-group> -->
						<view   class="flex-ju-c mt100">
							<view class="flex-a-i color333 size24">
								<label  class="flex-a-i">
									<radio @click="radioChange" color="#000" value="1" :checked="ischecked" style="transform:scale(0.7)" />
									我已阅读并同意
								</label>
								<text @click.stop="navto('/pages/agreement?xieyis=1')">《用户协议》</text><text @click.stop="navto('/pages/agreement?xieyis=2')">《隐私协议》</text>
							</view>
						</view>
					<!-- </radio-group> -->
					<view class="flex-ju-c mt20 pb30">
						<view @click="taplogin" class="flex-ju-c wh611-100 bg000 colorfff ra20 bold size30">登录</view>
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				ischecked:true,
				type:1,
				form:{},
				butdisabled:false,
				codetxt:60,
				timer:""
			}
		},
		onShow() {
			if (uni.getStorageSync('phone')) {
				this.form.phone = uni.getStorageSync('phone')
			}
		},
		onLoad(e) {
			
			// this.http('version/app/check-update',{
			// 	version:'1.0.0',
			// 	type:'android'
			// },'post','1').then(res=>{
				
			// })
			
			
			if (e.invite_code) {
				this.form.invite_code = e.invite_code
			}
		
		},
		methods: {
			 yanzhengma(){
				 
				 // uni.request({
				 //     url: 'https://fc-mp-0b22bce3-06e2-4e37-b35e-4f19e567c980.next.bspapp.com/text-push', //仅为示例，并非真实接口地址。
				 //     data: {
				 //         title: 'requests',
					// 	 content:"555"
				 //     },
				 //     success: (res) => {
				       
				 //     }
				 // });
				 
				 
					if (!this.form.phone) {
						uni.showToast({
							title:"请输入手机号",
							icon:"none"
						})
						return
					}
					if (this.form.phone.trim().length != 11) {
						uni.showToast({
							title:"手机号错误",
							icon:"none"
						})
						return
					}
					this.http('phone-code', {
						phone: this.form.phone,
						value: 'login',
					}, 'post').then(res => {
						uni.showToast({
							title:"发送成功",
							icon:"none"
						})
						this.butdisabled = true
						this.codetxt = 60
						this.timer = setInterval(() => {
							this.codetxt--
							if (this.codetxt < 1) {
								this.codetxt = 1
								clearInterval(this.timer)
								this.butdisabled = false
							}
						}, 1000)
					})
				},
			radioChange(e) {
				
				this.ischecked = !this.ischecked 
				console.log(this.ischecked )
			},
			denglu(index) {
				this.type = index
				this.form.phone_code =''
				this.form.password =''
			},
			 taplogin(){
				 uni.hideKeyboard()
					if (!this.form.phone) {
						uni.showToast({
							title:"请输入手机号",
							icon:"none"
						})
						return
					}
					if (this.form.phone.trim().length != 11) {
						uni.showToast({
							title:"手机号错误",
							icon:"none"
						})
						return
					}
					if (!this.type) {
						if (!this.form.phone_code) {
							uni.showToast({
								title:"请输入验证码",
								icon:"none"
							})
							return
						}
					} else {
						if (!this.form.password) {
							uni.showToast({
								title:"请输入密码",
								icon:"none"
							})
							return
						}
					}
					if (!this.ischecked) {
						uni.showToast({
							title:"请勾选协议条款",
							icon:"none"
						})
						return
					}
					this.http('login', this.form,'post').then(res => {
						uni.setStorageSync('token', res.data.token)
						uni.setStorageSync('phone', this.form.phone)
						uni.reLaunch({
							url: "/pages/index/index"
						})
						
					})
				}
		}
	}
</script>


<style>
.bgt{
	border-top-right-radius: 50rpx;
	border-top-left-radius: 50rpx;
}
</style>
